<template>
	<view class="content">
		<u-navbar
			title="首页"
			:autoBack="false"
			bgColor="#ffffff"
		></u-navbar>

		<view class="banner">
			<u-swiper
				:list="bannerList"
				height="300"
				:autoplay="true"
				:interval="3000"
				:duration="1000"
				:circular="true"
			></u-swiper>
		</view>

		<view class="grid-section">
			<u-grid :col="4" :border="false">
				<u-grid-item v-for="(item, index) in gridList" :key="index">
					<u-icon :name="item.icon" :size="46" color="#2979ff"></u-icon>
					<text class="grid-text">{{item.text}}</text>
				</u-grid-item>
			</u-grid>
		</view>

		<view class="card-section">
			<u-card
				v-for="(item, index) in cardList"
				:key="index"
				:title="item.title"
				:sub-title="item.subTitle"
				:thumb="item.thumb"
				@click="handleCardClick(item)"
			>
				<view slot="body" class="card-body">
					<text class="card-desc">{{item.description}}</text>
				</view>
			</u-card>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				bannerList: [
					'https://cdn.uviewui.com/uview/swiper/1.jpg',
					'https://cdn.uviewui.com/uview/swiper/2.jpg',
					'https://cdn.uviewui.com/uview/swiper/3.jpg'
				],
				gridList: [
					{ icon: 'home', text: '首页' },
					{ icon: 'star', text: '收藏' },
					{ icon: 'heart', text: '喜欢' },
					{ icon: 'setting', text: '设置' }
				],
				cardList: [
					{
						title: '热门推荐',
						subTitle: '2024-03-21',
						thumb: 'https://cdn.uviewui.com/uview/album/1.jpg',
						description: '这是一段描述文字，可以介绍相关内容。'
					},
					{
						title: '最新动态',
						subTitle: '2024-03-20',
						thumb: 'https://cdn.uviewui.com/uview/album/2.jpg',
						description: '这是另一段描述文字，展示更多信息。'
					}
				]
			}
		},
		onLoad() {
			// 页面加载时的逻辑
		},
		methods: {
			handleCardClick(item) {
				uni.showToast({
					title: `点击了${item.title}`,
					icon: 'none'
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #f5f5f5;
		min-height: 100vh;
	}

	.banner {
		margin: 20rpx;
		border-radius: 12rpx;
		overflow: hidden;
	}

	.grid-section {
		margin: 30rpx 20rpx;
		background-color: #ffffff;
		border-radius: 12rpx;
		padding: 20rpx 0;

		.grid-text {
			font-size: 24rpx;
			color: #333;
			margin-top: 10rpx;
		}
	}

	.card-section {
		margin: 20rpx;

		.card-body {
			padding: 10rpx 0;
		}

		.card-desc {
			font-size: 28rpx;
			color: #666;
			line-height: 1.5;
		}
	}
</style>
